package frontend.parser.node.expnode;

import frontend.parser.node.Node;

public class PrimaryExp extends Node {
    // PrimaryExp → '(' Exp ')' | LVal | Number

    public enum PrimaryExpType {
        PP_EXP, LVAL, NUMBER;
    }

    private PrimaryExpType primaryExpType;
    /* PP_EXP */
    private Exp exp;
    /* LVAL */
    private LVal lVal;
    /* NUMBER */
    private Number number;
    private int numberVal;

    public void addExp(Exp exp) {
        super.add(exp);
        this.primaryExpType = PrimaryExpType.PP_EXP;
        this.exp = exp;
    }

    public void addLVal(LVal lVal) {
        super.add(lVal);
        this.primaryExpType = PrimaryExpType.LVAL;
        this.lVal = lVal;
    }

    public void addNumber(Number number) {
        super.add(number);
        this.primaryExpType = PrimaryExpType.NUMBER;
        this.number = number;
        this.numberVal = number.getIntConstVal();
    }

    public PrimaryExpType getType() {
        return primaryExpType;
    }

    public Exp getExp() {
        return exp;
    }

    public LVal getlVal() {
        return lVal;
    }

    public Number getNumber() {
        return number;
    }

    public int getNumberVal() {
        return numberVal;
    }
}
